package com.jiangjiang.eshop.purchase.service.impl;

import com.jiangjiang.eshop.purchase.constant.PurchaseOrderStatus;
import com.jiangjiang.eshop.purchase.service.PurchaseFacadeService;
import com.jiangjiang.eshop.purchase.service.PurchaseOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName PurchaseFacadeServiceImpl
 * @Description TODO
 * @Author jhw
 * @Date 2021/9/13 23:08
 * @Version 1.0
 **/
@Slf4j
@Service
public class PurchaseFacadeServiceImpl implements PurchaseFacadeService {


    @Autowired
    private PurchaseOrderService purchaseOrderService;

    @Override
    public Boolean existRelatedPurchaseOrder(Long goodsSkuId) {
        return false;
    }

    @Override
    public Boolean informCreatePurchaseInputOrderEvent(Long purchaseOrderId) {
        try {
            return purchaseOrderService.updatePurchaseOrderStatus(purchaseOrderId, PurchaseOrderStatus.WAIT_FOR_INPUT);
        }catch (Exception e){
            log.warn("PurchaseFacadeServiceImpl informCreatePurchaseInputOrderEvent error",e);
        }
        return false;
    }

    @Override
    public Boolean informFinishedPurchaseInputOrderEvent(Long purchaseOrderId) {
        try {
            return purchaseOrderService.updatePurchaseOrderStatus(purchaseOrderId, PurchaseOrderStatus.FINISHED_INPUT);
        }catch (Exception e){
            log.warn("PurchaseFacadeServiceImpl informFinishedPurchaseInputOrderEvent error",e);
        }
        return false;
    }

    @Override
    public Boolean informCreatePurchaseSettlementOrderEvent(Long purchaseOrderId) {
        try {
            return purchaseOrderService.updatePurchaseOrderStatus(purchaseOrderId, PurchaseOrderStatus.WAIT_FOR_SETTLEMENT);
        }catch (Exception e){
            log.warn("PurchaseFacadeServiceImpl informCreatePurchaseSettlementOrderEvent error",e);
        }
        return false;
    }

    @Override
    public Boolean informFinishedPurchaseSettleOrderEvent(Long purchaseOrderId) {
        try {
            return purchaseOrderService.updatePurchaseOrderStatus(purchaseOrderId, PurchaseOrderStatus.FINISHED);
        }catch (Exception e){
            log.warn("PurchaseFacadeServiceImpl informFinishedPurchaseSettleOrderEvent error",e);
        }
        return false;
    }
}
